package com.ruoyi.classai.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.classai.domain.EwcChapterTeachingResources;
import com.ruoyi.classai.domain.dto.PublicIdQueryInterfaceDto;
import com.ruoyi.classai.domain.vo.EwcChapterVo;
import com.ruoyi.classai.domain.vo.LearningAnalytics.AnalyticsChapterTeachVo;
import com.ruoyi.classai.domain.vo.TodayCourseChapterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.classai.mapper.EwcChapterMapper;
import com.ruoyi.classai.domain.EwcChapter;
import com.ruoyi.classai.service.IEwcChapterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * 章节信息Service业务层处理
 * 
 * @author lcj
 * @date 2025-02-27
 */
@Service
public class EwcChapterServiceImpl extends ServiceImpl<EwcChapterMapper, EwcChapter> implements IEwcChapterService {

    @Autowired
    private EwcChapterMapper chapterMapper;

    @Override
    public List<EwcChapterVo> getChapterList(String courseId, String classId, String chapterName) {
        return chapterMapper.getChapterList(courseId,classId,chapterName);
    }

    @Override
    public List<TodayCourseChapterVo> getTodayCourseChapter(String teacherId, String today) {

        return chapterMapper.getTodayCourseChapter(teacherId,today);
    }


    @Override
    public boolean updateState(PublicIdQueryInterfaceDto publicIdQueryInterfaceDto) {
        EwcChapter chapter = new EwcChapter();
        chapter.setId(publicIdQueryInterfaceDto.getChapterUniqueId());
        chapter.setStatus(2);
        return this.updateById(chapter);
    }

    @Override
    public void updateEndClassState(PublicIdQueryInterfaceDto publicIdQueryInterfaceDto) {
        EwcChapter chapter = new EwcChapter();
        chapter.setId(publicIdQueryInterfaceDto.getChapterUniqueId());
        chapter.setStatus(3);
        this.updateById(chapter);
    }

    @Override
    public boolean updateChapterStatus(EwcChapter ewcChapter) {
        UpdateWrapper<EwcChapter> updateWrapper = new UpdateWrapper<>();
        // 设置更新条件
        updateWrapper.eq("id",ewcChapter.getId());
        updateWrapper.eq("course_id",ewcChapter.getCourseId());
        updateWrapper.eq("class_id",ewcChapter.getClassId());
        //设置更新数据
        EwcChapter entity = new EwcChapter();
        entity.setStatus(ewcChapter.getStatus());
        return this.update(entity,updateWrapper);
    }

    @Override
    public AnalyticsChapterTeachVo getChapterTeachInfo(EwcChapter ewcChapter) {
        return chapterMapper.getChapterTeachInfo(ewcChapter);
    }
}
